package com.cloudsigns.factorymanager2.engineering.presenter;

import com.cloudsigns.factorymanager2.engineering.IView.InRegionListView;

import com.cloudsigns.factorymanager2.engineering.bean.RegionBean;
import com.cloudsigns.factorymanager2.engineering.model.InRegionListModel;
import com.cloudsigns.factorymanager2.engineering.model.RegionListModel;

import java.util.List;

/**
 * Created by tony on 2018/5/5.
 */

public class RegionListPresenter {
    private InRegionListView view;
    private InRegionListModel model;
    private android.os.Handler mHandler = new android.os.Handler();

    public RegionListPresenter(InRegionListView view) {
        this.view = view;
        this.model = new RegionListModel();
    }

    public void getMediaRegionList() {
        view.showLoading();

        model.getMediaRegionList(new RegionListModel.OnMediaRegionListListener() {
            @Override
            public void getMediaRegionListSuccessed(final List<RegionBean> regionBeanList) {
                //需要在UI线程执行
                mHandler.post(new Runnable() {
                    @Override
                    public void run() {
                        view.getMediaRegionListSuccessed(regionBeanList);
                        view.hideLoading();
                    }
                });
            }

            @Override
            public void getMediaRegionListFailed(final String desc) {
                mHandler.post(new Runnable() {
                    @Override
                    public void run() {
                        view.showFailedError(desc);
                        view.hideLoading();
                    }
                });
            }


        });
    }
}
